﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
namespace WPFExcelReport
{
    //完成移库功能，从CP移入CW，同时进行包装
    /// <summary>
    /// 从CP移入CW，但是不进行WV03
    /// </summary>
    public partial class TWBMOV
    {

        public TWBMOV()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWBBST();
            this.DataContext = MV;
            InitializeComponent();
        }

        public void MOVE(DataRow _dwWB)
        {
            vwMaster.View.MoveCurrentTo(-1);
            TMV.MOVE(_dwWB, LO, LB, LP, this.RUNID);
        }
        public void MoveSelectedCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                IsSaved = false;//变更后，触发需要获取的界面的更新
                foreach (DataRow _dwWB in TBMain.Rows)
                {
                    if (_dwWB["WBBLB"].ToString() == LO)
                    {
                        continue;
                    }
                    TMV.MOVE(_dwWB, LO, LB, LP, this.RUNID);
                }
                TMV.VWBW.POSTCHG();
                IsSaved = true;//变更后，触发需要获取的界面的更新
                TBMain.Clear();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            filter = "WBBSTKNR='" + KEY + "'";
            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
        }
        public override void OnSTKNRChg(string value)
        {
            try
            {
                if (STKNR.Length == 0)
                    return;
                if (!IsAuto)
                    return;
                dwData = TBMain.NewRow();
                dwData["WBBMANDANT"] = app.Mandant;
                dwData["WBBSTKNR"] = STKNR;
                SResult = TMV.QueryWBBST(dwData, 13);
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    if (row["WBBLB"].ToString() == "KO")
                        throw new Exception("已发送至出货区，禁止移库");
                }
                MergeData(SResult, false, false);
                base.OnSTKNRChg(value);
            }
            catch (Exception ex)
            {
                INFO = ex.Message;
                Tracer.Error(ex.StackTrace, ex);
            }
        }
    }
}
